package ar.com.sudoku.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ArrayGrid extends Grid {

	private SudokuNumber[][] grid = new SudokuNumber[9][9];

	@Override
	public SudokuNumber get(SudokuNumber x, SudokuNumber y) {
		return grid[x.getValue() - 1][y.getValue() - 1];
	}

	@Override
	public void set(SudokuNumber x, SudokuNumber y, SudokuNumber number) {
		grid[x.getValue() - 1][y.getValue() - 1] = number;
	}

	@Override
	public Collection<SudokuNumber> getValues() {
		List<SudokuNumber> values = new ArrayList<SudokuNumber>();
		for (SudokuNumber[] list : grid) {
			for (SudokuNumber number : list) {
				if (number != null) {
					values.add(number);
				}
			}
		}
		return values;
	}
	
	@Override
	public Object clone() {
		Grid cloneGrid = new ArrayGrid();
		for (SudokuNumber x : SudokuNumber.values()) {
			for (SudokuNumber y : SudokuNumber.values()) {
				cloneGrid.set(x,y,this.get(x,y));
			}
		}
		return cloneGrid;
	}
}
